﻿using System;
using System.Globalization;

namespace Medianamik.UI
{
    public class BaseExternalPage : BasePage
    {
        #region Fields

        private const string UNIQUE_ID = "FC0802C4-DF7F-4851-877C-A95D2EB6A28E";

        #endregion

        protected override void InitializeCulture()
        {
            string controlId = Request["__EVENTTARGET"];
            string argument = Request["__EVENTARGUMENT"];

            if (!String.IsNullOrEmpty(controlId) && !String.IsNullOrEmpty(argument)
                && controlId == UNIQUE_ID)
            {
                SetCulture(argument);
            }

            base.InitializeCulture();
        }

        /// <Summary>
        /// Sets the current UICulture and CurrentCulture based on
        /// the arguments
        /// </Summary>
        /// <PARAM name="name"></PARAM>
        /// <PARAM name="locale"></PARAM>
        protected void SetCulture(string cultureName)
        {
            var culture = new CultureInfo(cultureName);
            ///<remarks>
            ///Saving the current thread's culture set by the User in the Session
            ///so that it can be used across the pages in the current application.
            ///</remarks>
            Session["MyCulture"] = culture;
        }

        protected override bool AuthenticatedPage
        {
            get
            {
                return false;
            }
        }
    }
}
